import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.naming.NamingException;

import unilearn.domain.Assignment;
import unilearn.domain.DataFile;
import unilearn.domain.Submission;
import unilearn.facade.AssignmentFacade;
import unilearn.facade.SubmissionFacade;

public class UserStories1
{
	public static void main(String[] args) throws SQLException, FileNotFoundException,
		NamingException
	{
		PrintWriter out = new PrintWriter(new FileOutputStream("UserStories1.txt"));
		try
		{
			if (args.length != 3)
			{
				System.err.println("Usage: " + UserStories1.class.getName()
						+ " studentNumber assignmentID submissionFile");
			}
			String studentID = args[0];

			String assignmentNoStr = args[1];
			long assignmentID = Long.parseLong(assignmentNoStr);

			String submissionZip = args[2];
			if (!submissionZip.endsWith(".zip")) { throw new IllegalArgumentException(
					"Zip files only accepted"); }
			File submissionFile = new File(submissionZip);

			Assignment ass = new Assignment(assignmentID);
			DataFile file = new DataFile();
			file.setFileID(1);

			Submission sub;
			sub = SubmissionFacade.createNewSubmission(ass, file, studentID, "1234567");

			ass = AssignmentFacade.getAssignmentBySubmission(sub);

			out.print("Student ID: ");
			out.println(sub.getStudentNumber());
			out.print("Subject: <Subject Name (");
			out.print(ass.getSubjectID());
			out.println(")>");
			out.println("Receipt No: " + sub.getSubmissionID());
			out.println("Received: " + sub.getDateSubmitted());
			out.println("Assignment: " + ass.getName());
			out.println("Attached: " + submissionFile.getName());
			out.println("Size: " + submissionFile.length());

			SubmissionFacade.deleteSubmission(sub);
		}
		finally
		{
			out.close();
		}
	}
}
